When creating source code of a program, a programmer typically declares variables using names and data types, and specifies functions that perform operations on the variables. In addition, the programmer may need to provide memory allocation for the variables. Because it is a manual process, a reference specified by the programmer may not be valid (e.g., may refer to a non-existent memory location, a variable being referenced may not be initialized, the memory location might have been freed, etc.). In some programming languages, it is possible to mismatch the types of the reference and the referenced object.
During runtime, when a function passes a reference to an object, the program may terminate abnormally if the reference was specified by the programmer incorrectly. In addition, the program may terminate abnormally if the object being referenced has a data type that is inconsistent with an operation that needs to be performed on the object by the function.
In some programming languages (e.g., C), debugging a problem caused by an invalid reference is not a trivial task because data type information is not available at runtime for certain variables. In particular, the data type information is only available in a few situations such as if local variables are initialized by explicit function calls. As to global and initialized automatic variables, they are initialized by the compiler and their data type information is not expressly stated in the object file created by the compiler.
The most common solution for the above problem uses heuristics to determine whether a reference passed by a function is for an object initialized by the compiler. If so, an error message is returned indicating that the reference is invalid. However, this solution leads to false positives because it does not account for references to objects initialized by the compiler that have a proper data type. Furthermore, the above solution cannot track references to objects that do not have a proper data type even though they were not initialized by the compiler.